package com.evil.application.enums.log;

import com.evil.application.pojo.entity.*;
import com.evil.common.log.enums.base.LogType;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Getter
@AllArgsConstructor
public enum ApplicationLogTypeEnum implements LogType {

    APPLICATION_PACKAGE(7000, "应用包表", ApplicationPackage.class),
    APPLICATION_GROUP(7001, "应用组表", ApplicationGroup.class),
    APPLICATION_INFO(7002, "应用表", ApplicationInfo.class),
    PACKAGE_APPLICATION(7003, "应用包应用表", PackageApplication.class),
    FAVOURITE_APPLICATION(7004, "用户常用应用表", FavouriteApplication.class),
    APPLICATION_APPLY_SETTING(7010, "应用提交设置表", ApplicationApplySetting.class),
    APPLICATION_NOTIFY_SETTING(7011, "应用提醒设置表", ApplicationNotifySetting.class),

    APPLICATION_FORM(7020, "应用表单表", ApplicationForm.class),
    APPLICATION_FORM_CONTROL(7021, "应用表单控件表", ApplicationFormControl.class),
    APPLICATION_FORM_SN_RULE(7022, "表单编号规则表", ApplicationFormSnRule.class),
    CONTROL_PERMISSION(7023, "控件权限配置表", ControlPermission.class),

    APPLICATION_PROCESS(7030, "应用流程表", ApplicationProcess.class),
    APPLICATION_PROCESS_NODE(7031, "应用流程节点表", ApplicationProcessNode.class),

    APPLICATION_VIEW(7040, "视图应用表", ApplicationView.class),
    APPLICATION_FILTER_GROUP(7041, "应用筛选组表", ApplicationFilterGroup.class),
    APPLICATION_FILTER_ITEM(7042, "应用筛选项表", ApplicationFilterItem.class),

    APPLICATION_BUTTON(7050, "自定义按钮表", ApplicationButton.class),

    APPLICATION_ROBOT(7060, "应用机器人表", ApplicationRobot.class),
    APPLICATION_ROBOT_RULE(7061, "机器人规则表", ApplicationRobotRule.class),
    APPLICATION_ROBOT_LOG(7062, "应用机器人日志表", ApplicationRobotLog.class),
    APPLICATION_ROBOT_LOG_DETAIL(7063, "应用机器人日志详细表", ApplicationRobotLogDetail.class),

    APPLICATION_TEMPLATE(7070, "打印模板表", ApplicationPrintTemplate.class),
    APPLICATION_IMPORT_TEMPLATE(7071, "导入模板表", ApplicationImportTemplate.class),

    APPLICATION_JUDGE(7080, "应用判断条件表", ApplicationJudge.class),

    APPLICATION_REPORTING(7090, "应用报表表", ApplicationReporting.class),

    APPLICATION_PERMISSION(7100, "应用权限表", ApplicationPermission.class),

    APPLICATION_QUEUE(7200, "应用队列表", ApplicationQueue.class),

    APPLICATION_ORDER(7500, "应用订单表", ApplicationOrder.class),
    APPLICATION_LOG(7501, "应用订单日志表", ApplicationOrderLog.class),
    APPLICATION_NODE(7502, "应用订单节点记录表", ApplicationOrderNode.class),
    APPLICATION_NODE_HANDLER(7503, "应用订单节点处理人表", ApplicationOrderNodeHandler.class),
    APPLICATION_ORDER_DATA(7504, "应用订单数据表", ApplicationOrderData.class),
    APPLICATION_ORDER_MESSAGE(7505, "应用订单留言表", ApplicationOrderMessage.class),
    ;

    private final int type;
    private final String name;
    private final Class<?> entityClass;

    public static Optional<ApplicationLogTypeEnum> isExistByType(Integer type) {
        if (null == type) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.type == type).findFirst();
    }

    public static Optional<ApplicationLogTypeEnum> isExistByClass(Class<?> entityClass) {
        if (null == entityClass) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> null != e.entityClass && e.entityClass.equals(entityClass)).findFirst();
    }

    public static ApplicationLogTypeEnum findByClass(Class<?> entityClass) {
        return ApplicationLogTypeEnum.isExistByClass(entityClass).orElseThrow(() -> LogType.error(entityClass));
    }
}
